home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / src / srgp_state_X.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  4.9 KB  |  188 lines

  1. #include "HEADERS.h"
  2. #include "srgplocal.h"
  3.  
  4. /** X11 VERSION OF state.c
  5. This contains no conditionally compiled code because it should be used
  6. only in the X11 version.
  7. **/
  8.  
  9.  
  10. static XWindowAttributes    srgpx__windowattrs;
  11. static XSetWindowAttributes    srgpx__setwindowattrs;
  12. static XSizeHints         srgpx__sizehints;
  13. static XWMHints            wm_hints;
  14.  
  15.  
  16. /** ERROR HANDLER FOR X SERVER EXCEPTIONS
  17. **/
  18.  
  19. int SRGP__handlerForXerrors (Display *d, XErrorEvent *err)
  20. {
  21.    char msg[80];
  22.  
  23.    XGetErrorText (d, err->error_code, msg, 80);
  24.    SRGP__error (ERR_X_SERVER, msg);
  25. }
  26.  
  27.  
  28.  
  29. void SRGP__initGraphicsDevice 
  30.    (char *name, int requested_planes, boolean debugasap)
  31. {
  32.    int cnt, i, j;
  33.    int width, height;
  34.    XEvent report;
  35.  
  36.    if ( (srgpx__display = XOpenDisplay(0)) == 0) {
  37.       fprintf (stderr, "unable to open to x server.\n");
  38.       exit(1);
  39.    }
  40.    
  41.    if (debugasap)
  42.       SRGP_enableSynchronous();
  43.       
  44.    XSetErrorHandler (SRGP__handlerForXerrors);
  45.  
  46.    srgpx__screen = DefaultScreen(srgpx__display);
  47.  
  48.    /* CREATE WINDOW FOR VIRTUAL SCREEN (canvas #0) */
  49.    srgp__curActiveCanvasSpec.drawable.win =
  50.       XCreateSimpleWindow (srgpx__display,
  51.                RootWindow(srgpx__display,srgpx__screen), 0,0,
  52.                width=srgp__curActiveCanvasSpec.max_xcoord+1,
  53.                height=srgp__curActiveCanvasSpec.max_ycoord+1,
  54.                1, 0L, 0L);
  55.  
  56.    SRGP__initColor (requested_planes);
  57.  
  58.  
  59.    /* SET GRAPHICS CONTEXT */
  60.    srgp__curActiveCanvasSpec.gc_frame =
  61.       XCreateGC (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  62.          0L, NULL);
  63.    srgp__curActiveCanvasSpec.gc_fill =
  64.       XCreateGC (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  65.          0L, NULL);
  66.  
  67.    /* INIT INPUT */
  68.    XSelectInput
  69.       (srgpx__display, srgp__curActiveCanvasSpec.drawable.win, 
  70.        ExposureMask|PropertyChangeMask);
  71.  
  72.    /* SET 0th CANVAS-WINDOW PROPERTIES */
  73.    srgpx__sizehints.flags = PSize | PMinSize | PMaxSize;
  74.    srgpx__sizehints.width = width;     srgpx__sizehints.height = height;
  75.    srgpx__sizehints.min_width = width; srgpx__sizehints.min_height = height;
  76.    srgpx__sizehints.max_width = width; srgpx__sizehints.max_height = height;
  77.    XSetStandardProperties
  78.       (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  79.        name, name, 0, 0, 0, &srgpx__sizehints);
  80.    wm_hints.flags = InputHint;
  81.    wm_hints.input = TRUE;
  82.    XSetWMHints (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  83.         &wm_hints);
  84.  
  85.    /* MAP...  Wait for the expose and property events */
  86.    XMapWindow (srgpx__display, srgp__curActiveCanvasSpec.drawable.win);
  87.    i=0; j=0;
  88.    do {
  89.       XNextEvent (srgpx__display, &report);
  90.       switch (report.type) {
  91.        case Expose:
  92.      if (report.xexpose.count == 0) i++; break;
  93.        case PropertyNotify:
  94.      j++; srgpx__starttime = srgpx__cur_time = report.xproperty.time; 
  95.      break;
  96.       }
  97.    } while (i==0 || j==0);
  98.  
  99.    /* No need for catching property events any more. */
  100.    XSelectInput
  101.       (srgpx__display, srgp__curActiveCanvasSpec.drawable.win, 
  102.        ExposureMask);
  103.  
  104.    /* We set up for backing store. */
  105.    srgpx__setwindowattrs.backing_store = Always;
  106.    XChangeWindowAttributes
  107.       (srgpx__display,
  108.        srgp__curActiveCanvasSpec.drawable.win,
  109.        CWBackingStore, &srgpx__setwindowattrs);
  110. }
  111.  
  112.  
  113.  
  114.  
  115. /** SRGP_refresh
  116. **/
  117.  
  118. void
  119. SRGP_refresh ()
  120. {
  121.    XSync (srgpx__display, FALSE);
  122.    SRGP__handleRawEvents (FALSE,FALSE);
  123. }
  124.  
  125.  
  126.  
  127. /** SRGP_enableSynchronous
  128. For use by a system administrator only.
  129. Puts X into synch. mode.
  130. **/
  131.  
  132. void
  133. SRGP_enableSynchronous ()
  134. {
  135.    XSynchronize (srgpx__display, 1);
  136.    XSync (srgpx__display, FALSE);
  137. }
  138.  
  139.  
  140.  
  141. /*!*/
  142.  
  143. static boolean resize_allowed = FALSE;
  144.  
  145. static void
  146. InformWindowManagerOfResizeStrategy()
  147. {
  148.    if (resize_allowed) {
  149.       srgpx__sizehints.flags = PMinSize | PMaxSize | PResizeInc;
  150.       srgpx__sizehints.min_width = 5; srgpx__sizehints.min_height = 5;
  151.       srgpx__sizehints.max_width = 5000; srgpx__sizehints.max_height = 5000;
  152.       srgpx__sizehints.width_inc = 1; srgpx__sizehints.height_inc = 1;
  153.       XSetStandardProperties
  154.      (srgpx__display, srgp__canvasTable[0].drawable.win,
  155.       NULL, NULL, 0, 0, 0, &srgpx__sizehints);
  156.    }
  157.    else {
  158.       int width = srgp__canvasTable[0].max_xcoord + 1;
  159.       int height = srgp__canvasTable[0].max_ycoord + 1;
  160.       srgpx__sizehints.flags = PSize | PMinSize | PMaxSize;
  161.       srgpx__sizehints.width = width;     srgpx__sizehints.height = height;
  162.       srgpx__sizehints.min_width = width; srgpx__sizehints.min_height = height;
  163.       srgpx__sizehints.max_width = width; srgpx__sizehints.max_height = height;
  164.       XSetStandardProperties
  165.      (srgpx__display, srgp__curActiveCanvasSpec.drawable.win,
  166.       NULL, NULL, 0, 0, 0, &srgpx__sizehints);
  167.    }
  168. }
  169.  
  170.  
  171. void
  172. SRGP_allowResize (boolean allow)
  173. {
  174.    resize_allowed = allow;
  175.    InformWindowManagerOfResizeStrategy();
  176. }
  177.  
  178.  
  179. void
  180. SRGP__forceScreenResize (int newwidth, int newheight)
  181. {
  182.    XResizeWindow (srgpx__display, srgp__canvasTable[0].drawable.win,
  183.           newwidth, newheight);
  184.    srgp__canvasTable[0].max_xcoord = newwidth - 1;
  185.    srgp__canvasTable[0].max_ycoord = newheight - 1;
  186.    InformWindowManagerOfResizeStrategy();
  187. }
  188.